// JavaScript Document


function selValue(obj) {
	if (obj.selectedIndex) {
		i = (obj.selectedIndex);
	} else {
		i = 0;
	}
	return obj.options[i].value;
}


function loadAccount(obj,lnk,conf) {
	
	ext = selValue(obj) ? '&uid=' + selValue(obj) : '';
	location = lnk + ext;
}

function trim(str) {
	if (str.length>0) {
		while (str.substring(0,1) == ' ') {
			str = str.substring(1, str.length);
		}
		while (str.substring(str.length-1, str.length) == ' ') {
			str = str.substring(0,str.length-1);
		}
	}
	return str;
}



function capitalize(str) {
	var newVal = '';
	str = str.split(' ');
	for(var c=0; c < str.length; c++) {
		newVal += str[c].substring(0,1).toUpperCase() + str[c].substring(1,str[c].length) + ' ';
	}
	return trim(newVal);
}



function capitalizeMe(obj) {
        var val = obj.value ;
        obj.value = capitalize(val);
}



function isNotEmail(str) {
   return ((str.indexOf(".") > 2) && (str.indexOf("@") > 0)) ? 0 : 1;
}

function chkMailFormat(obj) {
	var mail = obj.value;
	if (isNotEmail(mail) && mail) {
		alert('This email address does no seem to be correct. Please enter a valid email.');
		obj.value = '';
		obj.focus();
	}
}


function jNum(val) {
	var val = val.replace(/[^0-9.]/g,'');
	val = val ? val : 0;
	return val;
}

function jInput(obj) {
	var val = obj.value;
	val = val.replace(/[^0-9.]/g,'');
	val = val ? val : 0;
	obj.value = val;
}

function jClear(obj, val) {
	obj.value = val;
}

function jOut(obj, val) {
	val = parseFloat(obj.value) ? obj.value : val;
	obj.value = val;
}


function jAscii(char) {
	return char.charCodeAt(1);
}

function jFormat(val,dec) {
		if (dec < 0) {
			val = parseFloat(val) + '';
			dd = val.split('.');
			ll = dd[1] ? dd[1].length : 2;
			dec = (ll>2) ? ll : 2;
			dec = (ll<10) ? ll : 10;
		}
		val = parseFloat(val).toFixed(dec);
		x = val.split('.');
		
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		val = x1 + x2;
		return val;
	
}


function jFormatMe(obj,dec) {
	obj.value = jFormat(val,dec);
}